﻿using System;
using YawetagLib.Utilities;

namespace YawetagLib.Data.Xml
{
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
    public class XEntityAttribute : Attribute
    {
        public XEntityAttribute(Type entityType) 
        {
            EntityType = entityType;

            ContainerName = GetDefaultContainerName(entityType.Name);
            ElementName = GetDefaultElementName(entityType.Name);
            PrimaryKeyName = GetDefaultPrimaryKeyName(entityType.Name);
        }

        private static string GetDefaultContainerName(string entityName)
        {
            return entityName.ToCamelCase() + "s";
        }

        private static string GetDefaultElementName(string entityName)
        {
            return entityName.ToCamelCase();
        }

        private static string GetDefaultPrimaryKeyName(string entityName)
        {
            return entityName + "ID";
        }

        public Type EntityType { get; set; }

        public string ContainerName { get; set; }
        public string ElementName { get; set; }
        public string PrimaryKeyName { get; set; }
    }
}
